//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#ifndef __PS2MOUSE_H__
#define __PS2MOUSE_H__

#define MOUSEBUF    64

struct MouseData {
    UInt8 status;
    UInt8 x;
    UInt8 y;
    UInt8 reserve;
};

//
// Mouse
//
class Mouse : public CDeviceDriver
{
public:
    CARAPI Read(
        /* [in] */ Int64 u64Offset,
        /* [in] */ Int32 bytesToRead,
        /* [out] */ MemoryBuf * pBuffer,
        /* [out] */ IEvent * * ppCompletionEvent);

    CARAPI Write(
        /* [in] */ Int64 u64Offset,
        /* [in] */ const MemoryBuf & buffer,
        /* [out] */ Int32 * pBytesWritten,
        /* [out] */ IEvent * * ppCompletionEvent);

    CARAPI Control(
        /* [in] */ Handle32 nControlCode,
        /* [in] */ const MemoryBuf & inBuffer,
        /* [out] */ MemoryBuf * pOutBuffer,
        /* [out] */ IEvent * * ppCompletionEvent);

    virtual void Dispose() {}
    ;

public:
    Mouse() : m_receiveEvent()
    {
        memset(m_uMouseData, 0, sizeof(uint32_t) * MOUSEBUF);
        m_uHeader = 0;
        m_uTailer = 0;
        m_bWheel = FALSE;
    }

    ECode Initialize();

public:
    ioport_t        m_uPortBase;
    uint8_t         m_uIrq;

    bool_t          m_bWheel;
    uint32_t        m_uMouseData[MOUSEBUF];
    uint32_t        m_uHeader;
    uint32_t        m_uTailer;

    DzEvent           m_receiveEvent;
};

#endif /* __PS2MOUSE_H__ */
